package action.common;

import java.util.Map;

import org.apache.struts2.interceptor.SessionAware;
import org.springframework.security.context.SecurityContext;
import org.springframework.security.context.SecurityContextHolder;

import service.LoginService;

import com.opensymphony.xwork2.ActionSupport;

public class LoginAction extends ActionSupport implements SessionAware {

    private static final long serialVersionUID = 1L;

    private Map<String, Object> session;

    private LoginService loginService;
    
    private String loginState;

    public String login() throws Exception {

        SecurityContext sctx = SecurityContextHolder.getContext();
        String userName = sctx.getAuthentication().getName();
        Integer planId = loginService.getUserPlanId(userName);
        session.put("userPlanId", planId);
        return SUCCESS;
    }
    
    public String loginFail() throws Exception {
    	
    	loginState = "failure";
    	return SUCCESS;
    }

    public String getLoginState() {
		return loginState;
	}

	public void setLoginService(LoginService loginService) {
        this.loginService = loginService;
    }

    public void setSession(Map<String, Object> session) {
        this.session = session;
    }

}
